import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

// 获取原型对象上的push函数 修改原型对象中的push方法
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject);
  }
  return originalPush.call(this, location).catch(err => err);
};

const router = new Router({
  routes: [
    {
      path: "/",
      redirect: {
        name: "introduce"
      }
    },
    {
      name: "introduce",
      path: "/introduce",
      component: () => import("@/views/introduce.vue")
    },
    {
      name: "home",
      path: "/home",
      component: () => import("@/views/index.vue")
    },
    {
      name: "preview",
      path: "/preview",
      component: () => import("@/views/preview.vue")
    }
  ]
});

export default router;
